//
//  JWTStoreCourseView.m
//  JWT
//
//  Created by ndm on 17/2/10.
//  Copyright © 2017年 com.jwtsoft. All rights reserved.
//

#import "JWTStoreCourseView.h"

@implementation JWTStoreCourseView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
//        self.backgroundColor = RGBA(150, 151, 152, 1);;
        
        CGFloat shadow_height = 42;
        
        _courseInfoView = [[UIView alloc] init];
        [self addSubview:_courseInfoView];
        
        _courseImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_WIDTH*0.5)];
        [_courseImageView setImage:[UIImage imageNamed:ImageViewDefault]];
        [_courseInfoView addSubview:_courseImageView];
        
        _shadowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,  _courseImageView.bottom-shadow_height,_courseImageView.width, shadow_height)];
        _shadowImageView.backgroundColor = RGBA(0, 0, 0, 0.3);
        [_courseInfoView addSubview:_shadowImageView];
        
        _courseNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_shadowImageView.left, _shadowImageView.top+Cell_Margin*0.5, (_shadowImageView.width), (shadow_height-Cell_Margin)*0.5)];
        _courseNameLabel.text = @"";
        _courseNameLabel.textAlignment = NSTextAlignmentCenter;
        _courseNameLabel.textColor = RGB_WhiteBackGround;
        _courseNameLabel.font = Text_Font14;
        [_courseInfoView addSubview:_courseNameLabel];
        
        _coachNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_courseNameLabel.left, _courseNameLabel.bottom, _courseNameLabel.width, _courseNameLabel.height)];
        _coachNameLabel.font = Text_Font12;
        _coachNameLabel.text = @"";
        _coachNameLabel.textAlignment = NSTextAlignmentCenter;
        _coachNameLabel.textColor = RGB_WhiteBackGround;
        [_courseInfoView addSubview:_coachNameLabel];
        
        _price_person_backView = [[UIImageView alloc] initWithFrame:CGRectMake(self.left,_courseImageView.bottom, UISCREEN_WIDTH, 2*_courseNameLabel.height+3*Cell_Margin)];
        [_price_person_backView setImage:[ UIImage imageNamed:@"detail_head2_bg"]];
        [self addSubview:_price_person_backView];
        
        _coursePriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(Cell_Margin, Cell_Margin, (_shadowImageView.width-2*+Cell_Margin)*0.7, _courseNameLabel.height)];
        _coursePriceLabel.font = Text_Font15;
        _coursePriceLabel.text = @"";
        _coursePriceLabel.textColor = RGB_WhiteBackGround;
        _coursePriceLabel.textAlignment = NSTextAlignmentLeft;
        [_price_person_backView addSubview:_coursePriceLabel];
        
        _courseTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_courseImageView.left+Cell_Margin, _coursePriceLabel.bottom, _coursePriceLabel.width, 34)];
        _courseTimeLabel.font = Text_Font12;
        _courseTimeLabel.text = @"";
        _courseTimeLabel.backgroundColor = [UIColor clearColor];
        _courseTimeLabel.textColor = RGB_WhiteBackGround;
        [_price_person_backView addSubview:_courseTimeLabel];
        
        _coursePersonLabel = [[UILabel alloc] initWithFrame:CGRectMake(_coursePriceLabel.right, _coursePriceLabel.top, (_shadowImageView.width-2*Cell_Margin)*0.3, _coursePriceLabel.height)];
        _coursePersonLabel.textAlignment = NSTextAlignmentCenter;
        _coursePersonLabel.font = Text_Font16;
        _coursePersonLabel.text = @"";
        _coursePersonLabel.textColor = HeaderBackground_Color;
        [_price_person_backView addSubview:_coursePersonLabel];
        _coursePersonLabel.center = CGPointMake(_coursePersonLabel.center.x, _price_person_backView.height*0.5);
        _courseInfoView.backgroundColor = RGB_WhiteBackGround;
        
        //
        _courseRedView = [[UIView alloc] initWithFrame:CGRectMake(_price_person_backView.left+Cell_Margin, _price_person_backView.bottom+Cell_Margin, 4, 20)];
        _courseRedView.backgroundColor = HeaderBackground_Color;
        [_courseInfoView addSubview:_courseRedView];
        
        _introLabel = [[UILabel alloc] initWithFrame:CGRectMake(_courseRedView.right+Cell_Margin, _courseRedView.top, UISCREEN_WIDTH-_courseRedView.right-2*Cell_Margin, _courseRedView.height)];
        _introLabel.font = Text_Font15;
        [_courseInfoView addSubview:_introLabel];
        _courseRedView.center = CGPointMake(_courseRedView.center.x, _price_person_backView.bottom+Cell_Margin+(_introLabel.height*0.5));
        
        
        
        _courseTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_courseRedView.left, _courseRedView.bottom+2*Cell_Margin, UISCREEN_WIDTH-2*_coursePriceLabel.left, _courseRedView.height)];
        _courseTitleLabel.font = Text_Font14;
        [_courseInfoView addSubview:_courseTitleLabel];
        
        
        

        //
        _coachInfoView = [[UIView alloc] init];
        [self addSubview:_coachInfoView];
        
        _coachRedView = [[UIView alloc] initWithFrame:CGRectMake(_coursePriceLabel.left, Cell_Margin, _courseRedView.width, _courseRedView.height)];
        _coachRedView.backgroundColor = HeaderBackground_Color;
        [_coachInfoView addSubview:_coachRedView];
        
        _coachLabel = [[UILabel alloc] initWithFrame:CGRectMake(_coachRedView.right+Cell_Margin, _coachRedView.top, UISCREEN_WIDTH-_coachRedView.right-2*Cell_Margin, _coachRedView.height)];
        _coachLabel.font = Text_Font15;
        [_coachInfoView addSubview:_coachLabel];
        _coachLabel.center = CGPointMake(_coachLabel.center.x, _coachLabel.center.y);
        
        _coachImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_coachRedView.left, _coachLabel.bottom+2*Cell_Margin, 120, 120)];
        _coachImageView.layer.borderWidth= 0.5;
        [_coachInfoView addSubview:_coachImageView];
        
        _coachNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_coachImageView.right+Cell_Margin, _coachImageView.top+Cell_Margin, UISCREEN_WIDTH-_coachImageView.right-2*Cell_Margin, 34)];
        _coachNameLabel.font = Text_Font14;
        [_coachInfoView addSubview:_coachNameLabel];
        
        _coachSignLabel = [[UILabel alloc] initWithFrame:CGRectMake(_coachNameLabel.left, _coachNameLabel.bottom+Cell_Margin, _coachNameLabel.width, _coachNameLabel.height)];
        _coachSignLabel.font = Text_Font13;
        _coachSignLabel.textColor = RGB_LightGray;
        [_coachInfoView addSubview:_coachSignLabel];
        
        _coachInfoView.frame = CGRectMake(self.left, _courseInfoView.bottom+Cell_Margin, _courseInfoView.width, _coachImageView.bottom+Cell_Margin);
        _coachInfoView.backgroundColor = RGB_WhiteBackGround;
        
        //
        _storeInfoView = [[UIView alloc] init];
        [self addSubview:_storeInfoView];
        
        _storeRedView = [[UIView alloc] initWithFrame:CGRectMake(_coursePriceLabel.left, Cell_Margin, _courseRedView.width, _courseRedView.height)];
        _storeRedView.backgroundColor = HeaderBackground_Color;
        [_storeInfoView addSubview:_storeRedView];
        
        _storeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_storeRedView.right+Cell_Margin, _storeRedView.top, UISCREEN_WIDTH-_storeRedView.right-2*Cell_Margin, _storeRedView.height)];
        _storeLabel.font = Text_Font15;
        [_storeInfoView addSubview:_storeLabel];
        _coachLabel.center = CGPointMake(_storeLabel.center.x, _storeLabel.center.y);
        
        _storeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_storeRedView.left, _storeLabel.bottom+2*Cell_Margin, 120, 120)];
        _storeImageView.layer.borderWidth= 0.5;
        [_storeInfoView addSubview:_storeImageView];
        
        _storeNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_storeImageView.right+Cell_Margin, _storeImageView.top+Cell_Margin, UISCREEN_WIDTH-_storeImageView.right-2*Cell_Margin, 34)];
        _storeNameLabel.font = Text_Font14;
        [_storeInfoView addSubview:_storeNameLabel];
        
        _storeArressLabel = [[UILabel alloc] initWithFrame:CGRectMake(_storeNameLabel.left, _storeNameLabel.bottom+Cell_Margin, _storeNameLabel.width, _storeNameLabel.height)];
        _storeArressLabel.font = Text_Font13;
        _storeArressLabel.textColor = RGB_LightGray;
        [_storeInfoView addSubview:_storeArressLabel];
        
        _storeInfoView.frame = CGRectMake(self.left, _coachInfoView.bottom+Cell_Margin, _storeInfoView.width, _storeImageView.bottom+Cell_Margin);
        _storeInfoView.backgroundColor = RGB_WhiteBackGround;
        
        //
        _orderInfoView = [[UIView alloc] init];
        [self addSubview:_orderInfoView];
        
        _orderRedView = [[UIView alloc] initWithFrame:CGRectMake(_coursePriceLabel.left, Cell_Margin, _courseRedView.width, _courseRedView.height)];
        _orderRedView.backgroundColor = HeaderBackground_Color;
        [_orderInfoView addSubview:_orderRedView];
        
        _orderCourseLabel = [[UILabel alloc] initWithFrame:CGRectMake(_orderRedView.right+Cell_Margin, _orderRedView.top, UISCREEN_WIDTH-_orderRedView.right-2*Cell_Margin, _orderRedView.height)];
        _orderCourseLabel.font = Text_Font15;
        [_orderInfoView addSubview:_orderCourseLabel];
        
        _orderIconScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(_orderRedView.left, _orderCourseLabel.bottom+2*Cell_Margin, UISCREEN_WIDTH-2*Cell_Margin, 60)];
        _orderIconScrollView.layer.borderWidth = 0.5;
        _orderIconScrollView.scrollEnabled = YES;
        [_orderInfoView addSubview:_orderIconScrollView];
        
        _orderInfoView.frame = CGRectMake(self.left, _storeInfoView.bottom+Cell_Margin,UISCREEN_WIDTH, _orderIconScrollView.bottom+Cell_Margin);
        _orderInfoView.backgroundColor = RGB_WhiteBackGround;

        //
        
        _timeInfoView = [[UIView alloc] init];
        [self addSubview:_timeInfoView];
        
        _courseTimeRedView = [[UIView alloc] initWithFrame:CGRectMake(_coursePriceLabel.left, Cell_Margin, _courseRedView.width, _courseRedView.height)];
        _courseTimeRedView.backgroundColor = HeaderBackground_Color;
        [_timeInfoView addSubview:_courseTimeRedView];
        
        _courTimeTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_courseTimeRedView.right+Cell_Margin, _courseTimeRedView.top, UISCREEN_WIDTH-_courseTimeRedView.right-2*Cell_Margin, _courseTimeRedView.height)];
        _courTimeTitleLabel.font = Text_Font15;
        [_timeInfoView addSubview:_courTimeTitleLabel];
        
        _courTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_courseTimeRedView.left, _courTimeTitleLabel.bottom+2*Cell_Margin, UISCREEN_WIDTH-2*Cell_Margin, 34)];
        _courTimeLabel.font = Text_Font13;
        [_timeInfoView addSubview:_courTimeLabel];
        
        _timeInfoView.frame = CGRectMake(self.left, _orderInfoView.bottom+Cell_Margin, _orderInfoView.width, _courTimeLabel.bottom+Cell_Margin);
        _timeInfoView.backgroundColor = RGB_WhiteBackGround;

        self.frame = CGRectMake(self.left, self.top, UISCREEN_WIDTH, _timeInfoView.bottom+2*Cell_Margin);
    }
    return self;
}

/**
 初始化创建已预约人员的头像
 array 存放user模型
 */
-(void) createOrderedPersonScrollView:(UIScrollView *)scrollView  orderedArray:(NSMutableArray *) array{
    //移除所有子视图
    for (UIImageView *obj in scrollView.subviews) {
        if ([obj isKindOfClass:[UIImageView class]]) {
             [obj removeFromSuperview];
        }
    }
    
    int width = 50;
    
    for (int i = 0; i < array.count; i++) {
        JWTUserInfo *user = [JWTUserInfo mj_objectWithKeyValues:[array objectAtIndex:i]];
        UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake((Cell_Margin+width)*i+Cell_Margin, 6, width, width)];
        [icon sd_setImageWithURL:[[JWTAPPHttpsUrl sharedInstance] urlAppendString:user.icon] placeholderImage:[UIImage imageNamed:ImageViewDefault]];
        icon.contentMode = UIViewContentModeScaleAspectFit;
        icon.userInteractionEnabled = YES;
        icon.layer.borderWidth = 0.5;
        icon.layer.borderColor = RGB_LightGrayBackGround.CGColor;
        icon.layer.masksToBounds = YES;
        [scrollView addSubview:icon];
    }
}




@end
